package timer

import (
	"time"

	"github.com/project-flogo/core/data/coerce"
)

type Settings struct {
}

type HandlerSettings struct {
	StartInterval  string `md:"startDelay"`     // The start delay (ex. 1m, 1h, etc.), immediate if not specified
	RepeatInterval string `md:"repeatInterval"` // The repeat interval (ex. 1m, 1h, etc.), doesn't repeat if not specified
}

type Output struct {
	TickCount uint64    `json:"tickCount,omitempty"`
	Timestamp time.Time `json:"timestamp,omitempty"`
}

func (r *Output) ToMap() map[string]interface{} {
	return map[string]interface{}{
		"tickCount": r.TickCount,
		"timestamp": r.Timestamp.Format(time.RFC3339Nano),
	}
}

func (r *Output) FromMap(values map[string]interface{}) error {
	count, err := coerce.ToInt64(values["tickCount"])
	if err != nil {
		return err
	}
	r.TickCount = uint64(count)
	t, err := coerce.ToString(values["timestamp"])
	if err != nil {
		return err
	}
	timestamp, err := time.Parse(t, time.RFC3339Nano)
	if err != nil {
		return err
	}
	r.Timestamp = timestamp
	return nil
}

type Reply struct {
}
